package Selenium.MyAccount;
import java.util.concurrent.TimeUnit;
import Selenium.CommonFunctions.AdvanceFindElementFunctions;

import org.openqa.selenium.*;

//this class is for the registration form
public class RegistrationModuleClass {

	private WebDriver GenericWebDriver;
	public WebElement MainRegistrationForm;
	public RegistrationFormObjects RegistrationPageobjects;
	public boolean RegisterFrameExists;
	public boolean FirstNameEditBoxExists;
	public boolean LastNameEditBoxExists;
	public boolean PasswordEditBoxExists;
	public boolean RetypePasswordEditBoxExists;
	public boolean EmailIdEditBoxExists;
	public boolean AgreeCookieCheckBoxExists;
	public boolean MarketingCheckBoxExists;
	public boolean CreateAnAccountButtonExists;
	public boolean PrivacyPolicyLinkExists;
	public boolean SigninLinkExists;
	
	
	
	
	
	public RegistrationModuleClass(WebDriver GenericWebDriver)
	{
		this.GenericWebDriver = GenericWebDriver;
		RegistrationPageobjects  = new RegistrationFormObjects();	
		RegisterFrameExists = false;
		FirstNameEditBoxExists = false;
		LastNameEditBoxExists = false;
		PasswordEditBoxExists = false;
		RetypePasswordEditBoxExists = false;
		EmailIdEditBoxExists = false;
		AgreeCookieCheckBoxExists = false;
		MarketingCheckBoxExists = false;
		CreateAnAccountButtonExists = false;
		PrivacyPolicyLinkExists = false;
		SigninLinkExists = false;
		
		
		//trying to create a Register form
		try
		{
			GenericWebDriver.switchTo().frame(0);
			MainRegistrationForm = GenericWebDriver.findElement(By.id("register-iframe"));	
			RegisterFrameExists = true;
		}		
		catch(NoSuchElementException ex)
		{
			System.out.println("Register form was not found in Registration form");			
		}
		catch(Exception ex1)
		{
			System.out.println("Register form was not found in Registration form");			
		}
		AddElements();

	}
	
	
	public void AddElements()
	{
		
		
		//trying to create a firstName edit box
		try
		{
			RegistrationPageobjects.FirstNameEditBox = MainRegistrationForm.findElement(By.id("login-first-name"));	
			FirstNameEditBoxExists = true;
		}		
		catch(NoSuchElementException ex)
		{
			System.out.println("First name edit box was not found in Registration form");			
		}
		catch(Exception ex1)
		{
			System.out.println("First name edit box  was not found in Registration form");			
		}
		
		//trying to create a Last Name edit box
		try
		{
			RegistrationPageobjects.LastNameEditBox = MainRegistrationForm.findElement(By.id("login-last-name"));	
			LastNameEditBoxExists = true;
		}		
		catch(NoSuchElementException ex)
		{
			System.out.println("First name edit box was not found in Registration form");			
		}
		catch(Exception ex1)
		{
			System.out.println("First name edit box  was not found in Registration form");			
		}
		
		//trying to create a email address edit box
		try
		{
			RegistrationPageobjects.EmailIdEditBox = MainRegistrationForm.findElement(By.id("login-username"));	
			EmailIdEditBoxExists = true;
		}		
		catch(NoSuchElementException ex)
		{
			System.out.println("Email ID edit box was not found in Registration form");			
		}
		catch(Exception ex1)
		{
			System.out.println("Email ID edit box  was not found in Registration form");			
		}
		
		//trying to create a password edit box
		try
		{
			RegistrationPageobjects.PasswordEditBox = MainRegistrationForm.findElement(By.id("password"));	
			PasswordEditBoxExists = true;
		}		
		catch(NoSuchElementException ex)
		{
			System.out.println("Password edit box was not found in Registration form");			
		}
		catch(Exception ex1)
		{
			System.out.println("Password edit box  was not found in Registration form");			
		}
		
		
		
		//trying to create a retype password edit box
		try
		{
			RegistrationPageobjects.RetypePasswordEditBox = MainRegistrationForm.findElement(By.id("retype-password"));	
			RetypePasswordEditBoxExists = true;
		}		
		catch(NoSuchElementException ex)
		{
			System.out.println("Retype Password edit box was not found in Registration form");			
		}
		catch(Exception ex1)
		{
			System.out.println("Retype Password edit box  was not found in Registration form");			
		}
		
		//trying to create a Terms and conditions check box
		try
		{
			RegistrationPageobjects.AgreeCookieCheckBox = MainRegistrationForm.findElement(By.id("accept-terms"));	
			AgreeCookieCheckBoxExists = true;
		}		
		catch(NoSuchElementException ex)
		{
			System.out.println("Terms and conditions check box was not found in Registration form");			
		}
		catch(Exception ex1)
		{
			System.out.println("Terms and conditions check box was not found in Registration form");			
		}
		
		//trying to create a Marketing check box
		try
		{
			RegistrationPageobjects.MarketingCheckBox = AdvanceFindElementFunctions.FindElement(MainRegistrationForm, "label", "for", "accept-terms");
			//RegistrationPageobjects.MarketingCheckBox = MainRegistrationForm.findElement(By.id("accept-marketing"));	
			MarketingCheckBoxExists = true;
		}		
		catch(NoSuchElementException ex)
		{
			System.out.println("Marketing check box was not found in Registration form");			
		}
		catch(Exception ex1)
		{
			System.out.println("Marketing check box was not found in Registration form");			
		}
		
		
		//trying to create a submit button
		try
		{
			RegistrationPageobjects.CreateAnAccountButton = MainRegistrationForm.findElement(By.name("submit-sign-in"));	
			CreateAnAccountButtonExists = true;
		}		
		catch(NoSuchElementException ex)
		{
			System.out.println("Create and account button was not found in Registration form");			
		}
		catch(Exception ex1)
		{
			System.out.println("Create and account button was not found in Registration form");			
		}
		
		//trying to create a signin link
		
		//This part of the code depends on a common function library
		try
		{
			//RegistrationPageobjects.SigninLink = MainRegistrationForm.findElement(By.name("submit-sign-in"));	
			RegistrationPageobjects.SigninLink = AdvanceFindElementFunctions.FindElement(MainRegistrationForm, "a", "title", "Sign in");
			CreateAnAccountButtonExists = true;
		}		
		catch(NoSuchElementException ex)
		{
			System.out.println("SigninLink was not found in Registration form");			
		}
		catch(Exception ex1)
		{
			System.out.println("SigninLink was not found in Registration form");			
		}
	}
	
	
	
	
	///All the objects on the page
	public class RegistrationFormObjects
	{
		WebElement FirstNameEditBox;
		WebElement LastNameEditBox;
		WebElement PasswordEditBox;
		WebElement RetypePasswordEditBox;
		WebElement EmailIdEditBox;
		WebElement AgreeCookieCheckBox;
		WebElement MarketingCheckBox;	
		WebElement CreateAnAccountButton;
		WebElement PrivacyPolicyLink;
		WebElement SigninLink;
		
	}
	
}
